<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class DetailController extends Controller
{
    public function detail(Request $request){
        $gid=$request->input('gid');
        //dd($gid);
        $good=DB::table('goods')->where('gid','=',$gid)->first();
        $goodinfo=DB::table('goodinfo')->where('gid','=',$gid)->first();
        $tid=$good['tid'];
        $hotgoods=DB::table('goods')->where('tid','=',$tid)->take(8)->get();
        return view('home.detail',['good'=>$good,'goodinfo'=>$goodinfo,'hotgoods'=>$hotgoods]);
    }

    //添加到收藏
    public function collect(Request $request){
        $gid=$request->input('gid');

        $collect=$request->only(['uid','cotime','gid']);
        $collect['gid']=$gid;
        $uid=$request->session()->get('uid');
        $collect['uid']=$uid;
        $collect['cotime']=time();
        if($collect['uid']==""){
            echo 2;
        }else{
            $result=DB::table('collect')->insert($collect);
            if($result){
                echo 1;
            }else{
                echo 0;
            }
        }

    }

    //添加到购物车
    public function shopcar(Request $request){
        $gid=$request->input('gid');

        $shopcar=$request->only(['uid','createtime','gid']);
        $shopcar['gid']=$gid;
        $uid=$request->session()->get('uid');
        $shopcar['uid']=$uid;
        $shopcar['createtime']=time();
        if($shopcar['uid']==""){
            echo 2;
        }else{
            $result=DB::table('shopcar')->insert($shopcar);
            if($result){
                echo 1;
            }else{
                echo 0;
            }
        }
    }
}
